package vn.edu.uit.wifi_transfering;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

public class ServerAdapter extends BaseAdapter {

	private Context context;
	private LayoutInflater inflater;
	private String[] listServers;

	public ServerAdapter(Context ctx, String[] listServers) {
		this.context = ctx;
		this.inflater = LayoutInflater.from(ctx);
		this.listServers = listServers;
	}

	public int getCount() {
		return listServers.length;
	}

	public Object getItem(int pos) {
		return null;
	}

	public long getItemId(int pos) {
		return 0;
	}

	public class ViewHolder {
		public TextView title;
		public ImageView icon;
	}

	public View getView(int pos, View view, ViewGroup parent) {
		ViewHolder holder;
		if (view == null) {
			view = inflater.inflate(R.layout.item_of_grid, null);
			view.setLayoutParams(new GridView.LayoutParams(90,90));
			holder = new ViewHolder();
			holder.title = (TextView) view.findViewById(R.id.cell_name);
			holder.icon = (ImageView) view.findViewById(R.id.cell_icon);
			view.setTag(holder);
		} else {
			holder = (ViewHolder) view.getTag();
		}
		
		holder.icon.setAdjustViewBounds(true);
		holder.icon.setScaleType(ImageView.ScaleType.CENTER_CROP);
		holder.icon.setPadding(6, 6, 6, 6);
		holder.icon.setImageResource(R.drawable.network_connection);
		holder.title.setText(listServers[pos]);	
		holder.title.setContentDescription(listServers[pos]);
		return view;
	}

}
